package com.hdaccp.shuiguoD.controller;


import com.hdaccp.shuiguoD.entity.Kehu;
import com.hdaccp.shuiguoD.service.KehuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/info")
@Scope("prototype")
public class KehuController {

    @Autowired
    private KehuService kehuService;

    @RequestMapping("/queryAll")
    @ResponseBody
    public Map<String,Object> queryAll(int offset,int limit){
        /* Map<String,Object> map = new HashMap<>() ;
        map.put("rows",userInfoService.findAll(offset,limit)) ;
        map.put("total",userInfoService.findTotalCount()) ;
        return  map ;*/

        return null;
    }

  /*  @RequestMapping("/queryAll")
    @ResponseBody
    public List<Kehu> queryAll(){

        return kehuService.getAll();

    }
*/
    @RequestMapping("/querySearch")
    @ResponseBody
    public Map<String,Object> querySearch(String kname, int offset, int limit){
        Map<String,Object> map = new HashMap<>();
        map.put("rows",kehuService.findAll(kname,offset,limit));
        map.put("total",kehuService.findTotalCount(kname));
        return map;
    }

    @RequestMapping("/shanchu")
    @ResponseBody
    public int shanchu(int kid){
        return kehuService.delte(kid);
    }

    @RequestMapping("/inst")
    @ResponseBody
    public int inst(Kehu kehuinfo){
        return kehuService.zj(kehuinfo);
    }

    @RequestMapping("/xg")
    @ResponseBody
    public int xg(Kehu kehuinfo){
        System.out.println(kehuinfo.getKid()+"---");
        return kehuService.update(kehuinfo);
    }

    /**
     * 根据ID查询
     * @param kid
     * @return
     */
    @RequestMapping("/queryById")
    @ResponseBody
    public Kehu queryById(int kid){
        return kehuService.queryById(kid);
    }
}
